package com.example.trader.controller;


import com.example.trader.common.Result;
import com.example.trader.entity.Order;
import com.example.trader.service.OrderManagerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/trader")
@CrossOrigin(origins = "http://localhost:8080")
public class OrderManagerController {

    @Autowired
    private OrderManagerService orderManagerService;

    /**
     * 订单列表展示
     */
    @GetMapping("/getOrderListPage")
    public Result<PageInfo> getOrderListPage(@RequestParam(defaultValue = "1") Integer pageNumber, @RequestParam(defaultValue = "10") Integer pageSize) {
        PageHelper.startPage(pageNumber, pageSize);
        List<Order> orderList = orderManagerService.getOrderList();
        return Result.success(new PageInfo(orderList));
    }

    /**
     * 删除订单接口
     */

    @DeleteMapping("/deleteOrderById/{orderId}")
    public Result deleteOrderById(@PathVariable("orderId") Integer orderId) {
        orderManagerService.deleteOrderById(orderId);
        return Result.success("订单删除成功");
    }

    /**
     * 根据订单号查询
     */
    @GetMapping("/gerOrderById")
    public Result<PageInfo> getOrderById(@RequestParam("orderId") Integer orderId) {
        PageHelper.startPage(1, 10);
        List<Order> orderList = orderManagerService.getOrderById(orderId);
        return Result.success(new PageInfo(orderList));
    }

    /**
     * 修改订单状态
     */

    @PutMapping("/updateOrderStatus")
    public Result updateOrderStatus(@RequestBody Order order) {
        orderManagerService.updateOrderStatus(order);
        return Result.success("订单状态修改成功");
    }

    /**
     * 查看销售收入
     */
    @GetMapping("/getorders")
    public Result getOrders() {
        return null;
    }

}
